class Solution {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int start1 = 0;
        int start2 = 0;
        int len = nums1.length + nums2.length;
        int[] merged = new int[len];
        for (int i = 0; i <= len / 2; i++) {
            if (start1 >= nums1.length) {
                // start1 走到尽头 直接走start2++
                merged[i]=nums2[start2++];
                continue;
            }
            if (start2 >= nums2.length) {
                // start2 走到尽头 直接走 start1++
                merged[i]=nums1[start1++];
                continue;
            }
            if (nums1[start1] > nums2[start2]) {
                merged[i]=nums2[start2++];
            } else {
                merged[i]=nums1[start1++];
            }
        }
        return len%2==0 ? (double) (merged[len/2] + merged[len/2-1]) /2 : merged[len/2];
    }
}